package com.whale.api.impl;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.whale.api.IWebApiService;
import com.whale.api.WebApiUrlConfig;
import com.whale.entity.Comment;
import com.whale.entity.FollowCount;
import com.whale.entity.Image;
import com.whale.entity.Location;
import com.whale.entity.PostStream;
import com.whale.entity.Response;
import com.whale.entity.Stream;
import com.whale.entity.User;
import com.whale.util.HttpServerStatusException;
import com.whale.util.JSONUtil;
import com.whale.util.NetworkUtil;

public class DefaultWebApiService implements IWebApiService {

    @Override
    public Response<User> login(String email, String password) {
        Response<User> response;
        Map<String, String> paramMap = new HashMap<String, String>();
        paramMap.put("username", email);
        paramMap.put("password", password);
        try {
            String jsonString = NetworkUtil.post(WebApiUrlConfig.BASE_URL + WebApiUrlConfig.USER_LOGIN, paramMap);
            response = JSONUtil.convertStringForLogin(jsonString);
            if (!response.hasError) {
                response.data.email = email;
                response.data.password = password;
            }
        } catch (HttpServerStatusException e) {
            e.printStackTrace();
            response = new Response<User>();
            response.errorMsg = "网络错误";
        }
        return response;
    }

    @Override
    public boolean logout() {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public Response<User> register(String email, String name, String password, String rpassword) {
        Response<User> response;
        Map<String, String> paramMap = new HashMap<String, String>();
        paramMap.put("email", email);
        paramMap.put("name", name);
        paramMap.put("password", password);
        paramMap.put("rpassword", rpassword);
        try {
            String jsonString = NetworkUtil.post(WebApiUrlConfig.BASE_URL + WebApiUrlConfig.USER_REGISTER, paramMap);
            response = JSONUtil.convertStringForLogin(jsonString);
            if (!response.hasError) {
                response.data.email = email;
                response.data.password = password;
                response.data.name = name;
            }
        } catch (HttpServerStatusException e) {
            e.printStackTrace();
            response = new Response<User>();
            response.errorMsg = "网络错误";
        }
        return response;
    }

    @Override
    public Response<Stream> postStream(PostStream postStream) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Response<Stream> viewStream(String streamId) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Response<List<Stream>> viewOtherWall(String uid, String orderBy, int size) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Response<List<Stream>> viewSelfWall(String orderBy, int size) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Response<String> removeStream(String streamId) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Response<Location> getLocations(String streamId) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Response<Image> uploadImage(File imageFile) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Response<Image> uploadAvatar(File imageFile) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Response<List<Comment>> getComments(String sid, int offset, int size) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Response<String> removeComment(String id) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Response<Long> countComment(String sid) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Response<Comment> addComment(String sid, String content) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Response<List<User>> recommend() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Response<Object> addFollow(String fuid) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Response<Object> removeFollow(String fuid) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Response<List<User>> getFans(int offset, int size) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Response<Long> countFans(int offset, int size) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Response<List<User>> getMyFollows(int offset, int size) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Response<Long> countMyFollows(int offset, int size) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Response<List<User>> getMyFirends(int offset, int size) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Response<Long> countMyFirends(int offset, int size) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Response<FollowCount> countAll(int offset, int size) {
        // TODO Auto-generated method stub
        return null;
    }

}
